/******************* 公共变量 *******************/
var type = core.getUrlData('type');

/******************* Vue初始化代码 *******************/
var vm = new Vue({
	el: '.wrap',
	data: {
		setPw: '',
		confirmPw: '',
		type: type,
		btnJudge: true
	},
	methods: {
		checkPw: function (event) {
			var $this = $(event.target),
				thisIndex = $this.parent().index(),
				thisVal = $this.val();

			if (thisVal) {
				if ((type == 'login') ? core.pwJudge(thisVal) : thisVal.match(/\d{6}/)) {
					if (thisIndex) {
						if (thisVal != this.setPw) {
							core.layerHint('两次输入的密码不一致，请重新输入');
						}
					} else {
						if (thisVal != this.confirmPw) {
							core.layerHint('两次输入的密码不一致，请重新输入');
						}
					}
				} else {
					(type == 'login') ? core.layerHint('请输入6-16位，字母或数字密码') : core.layerHint('请输入6位纯数字密码');
				}
			} else {
				core.layerHint('输入密码不可为空');
			}
		},
		submit: function () {
			var _this = this;
			if (this.setPw == this.confirmPw) {
				if (this.btnJudge) {
					this.btnJudge = false;
					$.ajax({
						url: (type == 'login') ? userPwUrl : userPwUrl,
						type: 'post',
						data: {
							password: this.setPw,
							password1: this.confirmPw
						},
						success: function (data) {
							console.log(data)
							
							setTimeout(function () {
								_this.btnJudge = true;
							}, 1000);
							if (data.result == 1) {
								core.hintHref(data.message, userVerifyUrl);
							} else {
								core.layerHint(data.message);
							}
						}
					});
				}
			} else {
				core.layerHint('两次密码输入不一致，请重新输入');
			}
		}
	},
	computed: {
		
	},
	components: {
		
	},
	created: function () {
		
	},
	mounted: function () {
		common.bindBack();
	},
	updated: function () {
		
	}
});